package com.sample.dao;

import com.sample.entity.Company;
import com.sample.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author Keyon
 * @Date 2019/11/29 13:52
 * @Desc 用户-持久层
 */
@Repository
public interface UserDao {

    @Select("select * from user")
    List<User> findAll();

    //@Insert("insert into user (username,email) values (#{userName},#{email})")
    void saveUser(User user);

    @Select("select * from user where id = #{id}")
    User findUserById(Integer id);

    @Select("select * from user where companyId = #{companyId}")
    List<User> findUserByCompanyId(Integer companyId);

    @Update("update user set username=#{userName}, email = #{email} where id = #{id}")
    void updateUserById(User user);

    //@Delete("delete from user where id=#{id}")
    void deleteUserById(Integer id);

    @Select("select * from user")
    @Results(
            @Result(property = "company",
            column = "id",
            one = @One(select = "com.sample.dao.CompanyDao.findCompanyById")))
    List<User> findUserWithCompany();

    List<User> findAllUserWithCompany_XML();

    /*@Select("select * from user")
    @ConstructorArgs(value = {
            @Arg(column = "id", javaType = Integer.class),
            @Arg(column = "username", javaType = String.class),
            @Arg(column = "email", javaType = String.class),
            @Arg(column = "companyId", javaType = Company.class, typeHandler = )
    })
    List<User> findUserWithCompanyByConstructorArgs();*/

}
